import java.util.Arrays;

/**
 * @author LKQ
 * @date 2021/12/3 17:29
 * @description
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] digits = {4,9};
        solution.plusOne(digits);
    }

    public int[] plusOne(int[] digits) {
        int n = digits.length, temp = digits[n-1];
        for(int i=n-1; i>=0; i--) {
            if (temp!=9) {
                digits[i] += 1;
                break;
            }else {
                digits[i] = 0;
                if (i==0) {
                    digits[i] = 1;
                    int[] newDigits = Arrays.copyOf(digits, digits.length+1);
                    newDigits[digits.length] = 0;
                    digits = newDigits;
                }else {
                    temp = digits[i-1];
                }
            }
        }
        return digits;
    }
}
